package com.smh;

import org.junit.jupiter.api.Test;

import java.sql.Time;
import java.time.*;
import java.util.Timer;

/**
 * @author shiminghui
 * @date 2025/1/30 12:36
 * @description: TODO
 */
public class _003二维数组 {
    @Test
    public void test001() {
        int[][] arr = new int[1000_0][1000_0];

        Instant now = Instant.now();
        ij(arr);
        Instant now1 = Instant.now();
        System.out.println(Duration.between(now, now1).toNanos());

        Instant now2 = Instant.now();
        ji(arr);
        Instant now3 = Instant.now();
        System.out.println(Duration.between(now2, now3).toNanos());


    }

    public int ij(int[][] arr) {
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                sum += arr[i][j];
            }
        }
        return sum;
    }

    public int ji(int[][] arr) {
        int sum = 0;
        for (int j = 0; j < arr[0].length; j++) {
            for (int i = 0; i < arr.length; i++) {
                sum += arr[i][j];
            }
        }
        return sum;
    }
}
